import 'package:flutter_smart_heating/common/http.dart';

class GlobalData {
  // 基本配置
  static Map<String, dynamic> config = {};
  // 历史路由记录
  static List<String?> history = [];
  static List<dynamic> menu = [];
  static List<dynamic> substation = [];
  //未读徽标
  static Map<String, dynamic> badges = {};
  static Future init() async {
    await getConfig();
    await getBadge();
  }

  static Future refresh() async {
    await getBadge();
  }

  static getConfig() async {
    var res = await Http.instance.post('/plugin/app_manager/config/index');
    if (res.code == 1) {
      config = res.data;
    }
  }

  static getBadge() async {
    var res = await Http.instance.post('/plugin/messager/api/unRead');
    if (res.code == 1) {
      badges['messager'] = res.data['count'] ?? 0;
      badges['popup'] = res.data['popup'];
    }
  }
}
